#include "queue.h"

void InitQueue(Queue* q) {

    q->front = 0;
    q->rear = -1;
    q->size = 0;
}

bool IsEmpty(Queue* q) {

    return q->size == 0;
}

bool IsFull(Queue* q) {

    return q->size == MAX_SIZE;
}

void Enqueue(Queue* q, int value) {

    if (IsFull(q)) {
        printf("\nQueue is full.Cannot enqueue %d\n", value);
        return;
    }

    q->rear++;
    q->data[q->rear] = value;
    q->size++;
}

int DeQueue(Queue* q) {

    if (IsEmpty(q)) {
        printf("Queue is empty. Cannot dequeue\n");
        return -1;
    }
    int value = q->data[q->front];
    q->front++;
    q->size--;

    return value;
}

int GetHead(Queue* q) {

    if (IsEmpty(q)) {
        printf("\nQueue is empty. No element.\n");
        return -1;
    }
    return q->data[q->front];
}

void TraverseQueue(Queue* q) {

    if (IsEmpty(q)) {
        printf("\nQueue is empty. No element.\n");
        return ;
    }
    printf("Queue elements: ");
    for (int i = q->front; i <= q->rear; i++) {
        printf("%d ", q->data[i]);
    }
    printf("\n");
}

void ClearQueue(Queue* q) {
    q->front = 0;
    q->rear = -1;
    q->size = 0;
    printf("\nQueue has been cleared.\n");
}





